import { createRouter, createWebHashHistory } from 'vue-router'
import autoPage from '@/utils/auto-route'

import { useUserStore } from '@/stores/user'

// 导出路由
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: '/login', component: () => import('@/views/login/index.vue') },
    ...autoPage(),
    {
      path: '/',
      redirect: '/home',
    },
  ],
})

// 路由跳转之前
router.beforeEach((to, from) => {
  const userStore = useUserStore()

  // 登录拦截
  if (to.path == '/login') return
  if (!userStore.checkLogin()) return
})

export default router
